Rocks in a hydrocarbon reservoir can store hydrocarbons (for example, petroleum, oil, gas, or any combinations thereof) by trapping the hydrocarbons within porous formations in the rocks. Therefore, measurement results of the wettability of the rocks in a reservoir can be used to determine the potential productivity of the reservoir. The wettability can also be used to optimize extraction of the stored hydrocarbons from the reservoir in various steps of a production operation, such as water flooding and enhanced oil recovery (EOR).